const app = getApp()
import data from '../../utils/city.js';

Page({
  data: {

    TabCur: 0,
    MainCur: 0,
    VerticalNavTop: 0,
    list: [],
    load: true,
    filed: '',
    current: 15,
    showFlag: false,

    pinyin: [
      'A', 'B', 'C', 'F', 'G', 'H', 'J', 'L', 'N', 'Q', 'S', 'T', 'X', 'Y', 'Z',
      '全部',
    ],


    py2province: {
      A: ["安徽"],
      B: ["北京"],
      C: ["重庆"],
      F: ["福建"],
      G: ["甘肃", "广东", "广西", "贵州"],
      H: ["海南", "河北", "河南", "黑龙江", "湖北", "湖南"],
      J: ["吉林", "江苏", "江西"],
      L: ["辽宁"],
      N: ["内蒙古", "宁夏"],
      Q: ["青海"],
      S: ["山东", "山西", "陕西", "上海", "四川"],
      T: ["天津"],
      X: ["西藏", "新疆"],
      Y: ["云南"],
      Z: ["浙江"]
    },

    allProvince: ["安徽", "北京", "重庆", "福建", "甘肃", "广东", "广西", "贵州", "海南", "河北", "河南", "黑龙江", "湖北", "湖南", "吉林", "江苏", "江西", "辽宁", "内蒙古", "宁夏", "青海", "山东", "山西", "陕西", "上海", "四川", "天津", "西藏", "新疆", "云南", "浙江"],
    showProvince: [],
    allCity: {},
    showCity: []
  },
  onLoad: function(options) {
    console.log(options)
    let filed = options.filed;
    let allProvince = this.data.allProvince;
    let allCity = data['cityList']
    this.setData({
      filed,
      showProvince: allProvince,
      allCity
    })
    console.log(this.data.allCity)

  },
  onReady() {

  },
  //点击拼音获取省份
  showProvince: function(e) {
    let py = e.currentTarget.dataset.id;
    let index = e.currentTarget.dataset.index;
    console.log(py)
    let py2province = this.data.py2province;
    let all = this.data.allProvince;
    let province = [];
    if (py == "全部") {
      province = all;
    } else {
      province = py2province[py];
    }

    this.setData({
      current: index,
      showProvince: province
    })


  },
  //显示城市
  showCity: function(e) {
    let keyName = e.currentTarget.dataset.id;
    let allcity = this.data.allCity;
    let showCity = allcity[keyName]
    this.setData({
      showCity,
      showFlag: true
    })


  },
  //选择城市
  choseCity: function(e) {
    console.log(e)
    let item = e.currentTarget.dataset.item;
    console.log(item);
    let filed = this.data.filed;
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setdes(item)
    wx.navigateBack({
      delta: 1,
    })
  },
  //doNotMove
  doNotMove: function() {

  },
  toggleRight1() {
    this.setData({
      showFlag: !this.data.showFlag
    });
  },

})